package com.boot.controller;

import com.boot.DTO.DishDAO;
import com.boot.Vo.DishVo;
import com.boot.result.Result;
import com.boot.service.DishService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("dish")
public class DishController {
    @Autowired
    private DishService dishService;

    @Operation(summary = "新增菜品")
    @PostMapping()
    public Result save(@RequestBody DishDAO dishDAO) {
        return dishService.saveWithFlavor(dishDAO);
    }

    @Operation(summary = "获取菜品列表")
    @GetMapping("page")
    public Result page(DishVo dishVo) {
        return dishService.queryDishList(dishVo);
    }

    @Operation(summary = "根据id查询菜品")
    @GetMapping("/{id}")
    public Result findById(@PathVariable Long id) {
        return dishService.findById(id);
    }

    @Operation(summary = "根据分类获取菜品")
    @GetMapping("list")
    public Result findByCategory(@RequestParam Long categoryId) {
        return dishService.findByCategory(categoryId);
    }

    @Operation(summary = "删除菜品")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids) {
//        int[] idNums = Arrays.stream(ids.split(","))
//                .map(String::trim)
//                .mapToInt(Integer::parseInt)
//                .toArray();
        return dishService.deleteByIds(ids);
    }

    @Operation(summary = "启动售和停售菜品")
    @PostMapping("status/{status}")
    public Result updateStatus(@PathVariable Integer status,Integer id) {
        return dishService.updateStatus(id, status);
    }

    @Operation(summary = "修改菜品")
    @PutMapping()
    public Result updateDish(@RequestBody DishDAO dishDAO) {
        return dishService.updateDish(dishDAO);
    }

}
